package com.withoutwords.ui.custom;

import com.withoutwords.R;
import com.withoutwords.engine.Guess;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class GuessLayout extends RelativeLayout {

	private TextView txtName;
	private TextView txtGuessWord;
	Guess guess;
	IGuessClickListener guessListener;
	
	public GuessLayout(Context context)
	{
		super(context);
		init();
	}
	public GuessLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
		// TODO Auto-generated constructor stub
	}

	void init()
	{
		LayoutInflater inf =  LayoutInflater.from(getContext());
		inf.inflate(R.layout.guess_layout, this);
		txtName = (TextView)findViewById(R.id.txtViewName);
		txtGuessWord = (TextView)findViewById(R.id.txtViewGuessWord);
	}
	
	/*public void setGuess(Guess guess)
	{
		setGuess(guess,null);
	}*/
	public int getExpectedWidth()
	{
		float wid = 0;
		
		wid = txtGuessWord.getPaint().measureText(guess.wordGuess) + 50;//100 for buttons (approve and decline)
		return (int)wid;
	}
	public void setGuess(final Guess guess,IGuessClickListener l, boolean bshowApprove)
	{
		this.guess = guess;
		this.guessListener = l;
		txtName.setText(guess.playerName);
		txtGuessWord.setText(guess.wordGuess);
		
		if(this.guessListener != null)
		{
			if(bshowApprove)
			{
			ImageButton btnAprove = (ImageButton)findViewById(R.id.btnApprove);
			btnAprove.setVisibility(VISIBLE);
			btnAprove.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					guessListener.onActionApprovedClicked(guess);
					
				}
			});
			}
			ImageButton btnDecline = (ImageButton)findViewById(R.id.btnDecline);
			btnDecline.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					guessListener.onActionDeclinedClicked(guess);
					GuessLayout.this.setVisibility(INVISIBLE);
					
				}
			});
			
		}
		
		
		
	}
}
